package com.wei.frame.ui.lifecycle;

import java.util.concurrent.CancellationException;

import io.reactivex.Completable;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;

/**
 * 作者：赵若位
 * 时间：2020/8/20 10:48
 * 邮箱：1070138445@qq.com
 * 功能：
 */
final class Functions
{
    static final Function<Throwable, Boolean> RESUME_FUNCTION = throwable ->
    {
        if (throwable instanceof OutsideLifecycleException)
        {
            return true;
        }

        //noinspection ThrowableResultOfMethodCallIgnored
        Exceptions.propagate(throwable);
        return false;
    };

    static final Predicate<Boolean> SHOULD_COMPLETE = shouldComplete -> shouldComplete;

    static final Function<Object, Completable> CANCEL_COMPLETABLE = ignore -> Completable.error(new CancellationException());

    private Functions()
    {
        throw new AssertionError("No instances!");
    }
}
